package com.baselibrary.test.MVP.Main7Activity.presenter;

import com.baselibrary.libs.Utils.Toast.UtilsToast;
import com.baselibrary.libs.Utils.log.LogUtils;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queue.Request_netWork;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queue.Request_netWork_error;
import com.baselibrary.libs.Utils.netUtils.NoHttp.queueList.QueueNetWork;
import com.baselibrary.libs.base.baseMvp.BaseP.BaseP;
import com.baselibrary.libs.design_mode.Observable_demo.Observer.BaseObserver;
import com.baselibrary.libs.design_mode.Observable_demo.Observer.MyObserver;
import com.baselibrary.libs.design_mode.Observable_demo.Observer.NetTool;
import com.baselibrary.test.MVP.Main7Activity.chengshibean;
import com.baselibrary.test.MVP.Main7Activity.contract.Main7Contract;
import com.baselibrary.test.MVP.Main7Activity.model.Main7Model;
import com.baselibrary.test.MVP.Main7Activity.sohu;
import com.baselibrary.test.app.AppContext;

import java.util.Hashtable;

/**
 * Created by Administrator 于萌萌
 * 创建日期: 16:46 . 2017年02月24日
 * 描述:
 * <p>
 * <p>
 * 备注:
 */
public class Main7Presenter extends BaseP<Main7Contract.View> implements Main7Contract.Presenter {
    private final QueueNetWork mControlQueue;
    private MyObserver mObserver1;
    private MyObserver mObserver2;

    private Main7Model mModel;
    Main7Contract.View view;

    public Main7Presenter(Main7Contract.View view) {
        super(view);
        mControlQueue =
        AppContext.getmControlQueue();
    }

    @Override
    public void getV(Main7Contract.View view) {
        this.view = view;
    }

    @Override
    public void getM() {
        mModel = new Main7Model();
    }


    @Override
    public void getNet() {

         String url1 = AppContext.getUrl()+"123.txt";
         String url2 = AppContext.getUrl()+"1234.txt";
        Hashtable<String, String> hashtable = new Hashtable<>();


//        mObserver1 = new MyObserver(netWork1, chengshibean.class,new BaseObserver.CallBack<chengshibean>() {
//
//            @Override
//            public void succeed(chengshibean chengshibean) {
//                LogUtils.i("现在是我\t"+"mObserver1"+"专属成功是"+chengshibean);
//            }
//
//            @Override
//            public void updata(int updata) {
//                LogUtils.i("现在是我\t"+"mObserver1"+"专属过程是"+updata);
//            }
//
//            @Override
//            public void failure(Request_netWork_error o) {
//                LogUtils.i("现在是我\t"+"mObserver1"+"专属失败是"+o);
//            }
//
//            @Override
//            public void start() {
//                LogUtils.i("现在是我\t"+"mObserver1"+"专属开始是"+Thread.currentThread().getName());
//            UtilsToast.showToast(AppContext.getApplication(),"mObserver1开始");
//            }
//        });
        Request_netWork netWork = new Request_netWork("chengshibean", url1, hashtable);
        //是否设置 和 显示 缓存
        netWork.setCahce(chengshibean.class);

        NetTool.getInstances().getRequests()
                .jsonBean(chengshibean.class)
                .setRequests(netWork)
                .sendRequests(new BaseObserver.CallBack<chengshibean>() {
                    @Override
                    public void succeed(chengshibean chengshibean) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属成功是"+chengshibean);
                       view.succeed(chengshibean);
                    }

                    @Override
                    public void updata(int updata) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属过程是"+updata);
                    }

                    @Override
                    public void failure(Request_netWork_error o) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属失败是"+o);
                    }

                    @Override
                    public void start(Request_netWork observable, chengshibean chengshibean) {
                        LogUtils.i("现在是我\t"+"mObserver1"+"专属开始是"+Thread.currentThread().getName());
                        LogUtils.i("缓存\t"+"mObserver1"+"专属开始是"+chengshibean);
                      //  Object clazz = ()observable.getClazz();

                        UtilsToast.showToast(AppContext.getApplication(),"mObserver1开始");
                        if (null!=chengshibean)
                        view.succeed(chengshibean);
                    }

                });

        mControlQueue.add(netWork);
        Request_netWork netWork1 = new Request_netWork("sohu", url2, hashtable);
        //是否设置 和 显示 缓存
        netWork1.setCahce(sohu.class);

        NetTool.getInstances().getRequests()
                .jsonBean(sohu.class)
                .setRequests(netWork1)
                .sendRequests(new BaseObserver.CallBack<sohu>() {
                    @Override
                    public void succeed(sohu chengshibean) {
                        LogUtils.i("现在是我\t"+"mObserver2"+"专属成功是"+chengshibean);
                       view.succeed1(chengshibean);
                    }

                    @Override
                    public void updata(int updata) {
                        LogUtils.i("现在是我\t"+"mObserver2"+"专属过程是"+updata);
                    }

                    @Override
                    public void failure(Request_netWork_error o) {
                        LogUtils.i("现在是我\t"+"mObserver2"+"专属失败是"+o);
                        UtilsToast.showToast(AppContext.getApplication(),o.getMsg());
                    }

                    @Override
                    public void start(Request_netWork observable, sohu chengshibean) {
                        LogUtils.i("现在是我\t"+"mObserver2"+"专属开始是"+Thread.currentThread().getName());
                        LogUtils.i("缓存\t"+"mObserver2"+"专属开始是"+chengshibean);
                      //  Object clazz = ()observable.getClazz();

                        UtilsToast.showToast(AppContext.getApplication(),"mObserver1开始");
                        if (null!=chengshibean)
                        view.succeed1(chengshibean);
                    }

                });

        mControlQueue.add(netWork1);






    }
}
